package JavaDowork.pratice6;

public class Q1 {

    public static void main(String[] args) {
        // 定义一个整型数组并初始化
        int[] numbers = {8, 6, 2, 3, 1, 5, 7, 4};

        // 输出第4个元素和最后一个元素的值
        System.out.println("第4个元素的值：" + numbers[3]);
        System.out.println("最后一个元素的值：" + numbers[numbers.length - 1]);

        // 遍历输出数组元素
        System.out.println("正序遍历：");
        for (int i = 0; i < numbers.length; i++) {
            System.out.print(numbers[i] + " ");
        }

        // 倒序遍历输出数组元素
        System.out.println("\n倒序遍历：");
        for (int i = numbers.length - 1; i >= 0; i--) {
            System.out.print(numbers[i] + " ");
        }

        // 输出数组中的最大值和最小值
        int max = numbers[0];
        int min = numbers[0];
        for (int i = 1; i < numbers.length; i++) {
            if (numbers[i] > max) {
                max = numbers[i];
            }
            if (numbers[i] < min) {
                min = numbers[i];
            }
        }
        System.out.println("\n最大值：" + max);
        System.out.println("最小值：" + min);
    }
}
